home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Frameworks / TransSkel 3.24 / Source / SkelEvents.c < prev    next >
Text File  |  1996-01-17  |  2KB  |  75 lines

  1. /*
  2.  * SkelDoEvents (mask) - process all pending events of types indicated in mask
  3.  * SkelDoUpdates () - process all pending update events
  4.  *
  5.  * These routines may be called any time subsequent to the call of SkelInit().
  6.  */
  7.  
  8. # include    "TransSkel.h"
  9.  
  10.  
  11. static short    sdeMask;
  12.  
  13.  
  14. /*
  15.  * Make sure any events of proper type are processed before
  16.  * proceeding.  I.e., wait until there are no more events of the
  17.  * type we're waiting for, then terminate SkelDoEvents().
  18.  */
  19.  
  20. static pascal void
  21. CheckEvents (void)
  22. {
  23. EventRecord    event;
  24.  
  25.     if (!EventAvail (sdeMask, &event))
  26.         SkelStopEventLoop ();
  27. }
  28.  
  29.  
  30. /*
  31.  * Process all events of type(s) given in mask.  It is possible to call this
  32.  * recursively.
  33.  * Operation:
  34.  * - Save current SkelDoEvents() mask, current TransSkel event mask, and
  35.  * current background procedure.
  36.  * - Install the new mask into TransSkel and save a copy in a local variable.
  37.  * Install a new background procedure that checks whether any events of the
  38.  * desired type(s) are available or not.
  39.  * - Call SkelMain() to initiate an event loop.  The background task calls
  40.  * SkelWhoa() to terminate SkelMain() when there are no more events of
  41.  * interest available.
  42.  * - Restore the previous background procedure and TransSkel mask, and
  43.  * previous SkelDoEvents() mask.  The latter is necessary in case this is
  44.  * a recursive call.
  45.  */
  46.  
  47. pascal void
  48. SkelDoEvents (short mask)            /* can be called recursively */
  49. {
  50. short    oldSdeMask;
  51. short    oldTSMask;
  52. SkelIdleProcPtr    oldIdle;
  53.  
  54.     oldIdle = SkelGetIdle ();            /* get current idle proc */
  55.     oldTSMask = SkelGetEventMask ();    /* and event mask */
  56.     oldSdeMask = sdeMask;                /* and SkelDoEvents() processing types */
  57.  
  58.     SkelSetIdle (CheckEvents);            /* install new idle & mask */
  59.     SkelSetEventMask (mask);
  60.     sdeMask = mask;                        /* <- so CheckEvents can find mask */
  61.  
  62.     SkelEventLoop ();                    /* handle given event types only */
  63.  
  64.     SkelSetIdle (oldIdle);                /* restore stuff that was changed */
  65.     SkelSetEventMask (oldTSMask);
  66.     sdeMask = oldSdeMask;
  67. }
  68.  
  69.  
  70. pascal void
  71. SkelDoUpdates (void)
  72. {
  73.     SkelDoEvents (updateMask);
  74. }
  75.